﻿//===============================================================================
// Microsoft patterns & practices Enterprise Library Contribution
// Query Application Block
//===============================================================================

using System.Collections.Generic;
using System.Configuration;
using System.Management.Instrumentation;

namespace EntLibContrib.Query.Configuration.Manageability.Commands
{
	/// <summary>
	/// Represents an instance of <see cref="EntLibContrib.Query.Configuration.ServiceCustomCommandData"/>
	/// as an instrumentation class.
	/// </summary>
	[ManagementEntity]
	public class ServiceCustomCommandSetting : CustomCommandSetting
	{
		#region Construction
		/// <summary>
		/// Initialize a new instance of the <see cref="ServiceCustomCommandSetting"/> class with the
		/// command configuration, the name of the command and the command class type.
		/// </summary>
		/// <param name="sourceElement">The command configuration.</param>
		/// <param name="name">The name of the command.</param>
		/// <param name="commandTypeName">Name of the command type.</param>
		public ServiceCustomCommandSetting(ServiceCustomCommandData sourceElement,
																			 string name,
																			 string commandTypeName)
			: base(sourceElement, name, commandTypeName)
		{
		}
		#endregion

		#region Public Static Methods
		/// <summary>
		/// Returns an enumeration of the published <see cref="ServiceCustomCommandSetting"/> instances.
		/// </summary>
		/// <returns>Enumerable list of <see cref="ServiceCustomCommandSetting"/> instances</returns>
		[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")]
		[ManagementEnumerator]
		public static IEnumerable<ServiceCustomCommandSetting> GetInstances()
		{
			return GetInstances<ServiceCustomCommandSetting>();
		}

		/// <summary>
		/// Returns the <see cref="ServiceCustomCommandSetting"/> instance corresponding to the provided values for the key properties.
		/// </summary>
		/// <param name="applicationName">Name of the application.</param>
		/// <param name="sectionName">Name of the section.</param>
		/// <param name="name">The command name.</param>
		/// <returns>
		/// The published <see cref="ServiceCustomCommandSetting"/> instance specified by the values for the key properties,
		/// or <see langword="null"/> if no such an instance is currently published.
		/// </returns>
		[ManagementBind]
		public static ServiceCustomCommandSetting BindInstance(string applicationName,
																													 string sectionName,
																													 string name)
		{
			return BindInstance<ServiceCustomCommandSetting>(applicationName, sectionName, name);
		}
		#endregion

		#region Protected Methods
		/// <summary>
		/// Saves the changes on the <see cref="ServiceCustomCommandSetting"/> to its corresponding configuration object.
		/// </summary>
		/// <param name="sourceElement">The configuration object on which the changes must be saved.</param>
		/// <returns>
		/// 	<see langword="true"/> if changes have been saved, <see langword="false"/> otherwise.
		/// </returns>
		/// <remarks>Must be overridden by subclasses to perform the actual save.</remarks>
		protected override bool SaveChanges(ConfigurationElement sourceElement)
		{
			return ServiceCustomCommandDataWmiMapper.SaveChanges(this, sourceElement);
		}
		#endregion
	}
}
